package com.tianji.promotion.controller;


import com.tianji.common.domain.dto.PageDTO;
import com.tianji.promotion.domain.dto.CouponFormDTO;
import com.tianji.promotion.domain.dto.CouponIssueFormDTO;
import com.tianji.promotion.domain.query.CouponQuery;
import com.tianji.promotion.domain.vo.CouponDetailVO;
import com.tianji.promotion.domain.vo.CouponPageVO;
import com.tianji.promotion.domain.vo.CouponVO;
import com.tianji.promotion.service.ICouponService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

/**
 * <p>
 * 优惠券的规则信息 前端控制器
 * </p>
 *
 * @author WFan
 * @since 2025-04-03
 */
@Api(tags = "优惠券相关接口")
@RestController
@RequestMapping("/coupons")
@RequiredArgsConstructor
public class CouponController {
    private final ICouponService couponService;

    /**
     * 新增优惠券
     * @param couponFormDTO
     */
    @ApiOperation("新增优惠券接口")
    @PostMapping
    public void createCoupon(@RequestBody @Valid CouponFormDTO couponFormDTO) {
        this.couponService.createCoupon(couponFormDTO);
    }

    /**
     * 分页查询优惠券列表
     * @param query
     * @return
     */
    @GetMapping("page")
    @ApiOperation("分页查询优惠券列表")
    public PageDTO<CouponPageVO> queryCouponPage(CouponQuery query){
        return couponService.queryCouponPage(query);
    }

    /**
     * 发放优惠券
     * @param id
     */
    @PutMapping("{id}/issue")
    @ApiOperation("发放优惠券")
    public void issueCoupon(@PathVariable("id") Long id, @RequestBody @Valid CouponIssueFormDTO issueFormDTO){
        couponService.issueCoupon(id, issueFormDTO);
    }

    /**
     * 修改优惠券
     * @param id
     * @param couponFormDTO
     */
    @PutMapping("{id}")
    @ApiOperation("修改优惠券")
    public void updateCoupon(@PathVariable("id") Long id, @RequestBody @Valid CouponFormDTO couponFormDTO){
        couponService.updateCoupon(id,couponFormDTO);
    }

    /**
     * 根据id查询优惠券
     * @param id
     * @return
     */
    @GetMapping("{id}")
    @ApiOperation("根据id查询优惠券")
    public CouponDetailVO queryCouponById(@PathVariable("id") Long id){
        return couponService.queryCouponById(id);
    }

    /**
     * 删除优惠券
     * @param id
     */
    @DeleteMapping("{id}")
    @ApiOperation("删除优惠券")
    public void deleteCouponById(@PathVariable("id") Long id){
        couponService.deleteCouponById(id);
    }

    /**
     * 暂停优惠券发放
     * @param id
     */
    @PutMapping("{id}/pause")
    @ApiOperation("暂停优惠券发放")
    public void pauseCoupon(@PathVariable("id") Long id){
        couponService.pauseCoupon(id);
    }

    /**
     * 查询发放中的优惠券
     * @return
     */
    @GetMapping("list")
    @ApiOperation("查询优惠券列表")
    public List<CouponVO> queryCouponList(){
        return couponService.queryCouponList();
    }
}
